﻿//双击事件
function CustomDbClick() {
    //parent.closeWin(); //去掉双击功能
    fnViewDetail();
}


//新增
var fnCustomAdd = function () {
    const_EditEntity = "TrQuestionnaire";
    var pagetitle = "新增问卷";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=add"));
    parent.NeedRefreshPage = this;

}

//编辑
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }

    const_EditEntity = "TrQuestionnaire";
    //debugger
    //是否有引用
    YAHOO.util.Connect.asyncRequest('POST', "../TR/trAjax.aspx?flag=isquestionnaireused" + "&ID=" + record.getData(const_entityID), {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {
                    //没有引用，则可以修改
                    var pagetitle = "修改问卷_" + record._oData["QuestionnaireName"];
                    var deptName = record._oData["DeptName"];
                    parent._employeeTitle = pagetitle;
                    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=edit" + "&id=" + record.getData(const_entityID) + "&deptName=" + deptName));
                    parent.NeedRefreshPage = this;
                }
                else {
                    alert(str);
                    return;
                }
            }
            catch (e) {
                alert("读取失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);

}

//查看
var fnViewDetail = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "TrQuestionnaire";
    //debugger
    var pagetitle = "查看问卷_" + record._oData["QuestionnaireName"];
    var deptName = record._oData["DeptName"];
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=view" + "&id=" + record.getData(const_entityID) + "&deptName=" + deptName));
    parent.NeedRefreshPage = this;
}

//删除
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //debugger;
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        //this.getRecordSet()._records[0]._oData["BarItem"]
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }
    if (elist.length == 0) {
        alert("请至少选择一条记录删除！");
        return;
    }

    var id = record.getData(const_entityID);
    //第一步先删除相关的引用表信息、子表、主表
    YAHOO.util.Connect.asyncRequest('POST', "../TR/trAjax.aspx?flag=deletequestionnaire" + "&json=" + elist.join(","), {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    //第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                        SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
                        YAHOO.example.container.dialog3.show();
                    }
                }
                else {
                    alert(str);
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}


//问卷题目
var fnTrQuestionnaireSubject = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }

    var items = record.getData("SubjectSum");
    var url = "../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_TrQuestionnaireSubject&id=" + record.getData(const_entityID) + "&its=" + items + "";
    //是否有引用
    YAHOO.util.Connect.asyncRequest('POST', "../TR/trAjax.aspx?flag=isquestionnaireused" + "&ID=" + record.getData(const_entityID), {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {
                    //没有引用，则可以修改
                    var pagetitle = "问卷题目编辑_" + record._oData["QuestionnaireName"];
                    var deptName = record._oData["DeptName"];
                    parent._employeeTitle = pagetitle;
                    parent.addTabs(pagetitle, encodeURI(url));
                    parent.NeedRefreshPage = this;
                }
                else {
                    alert(str);
                    return;
                }
            }
            catch (e) {
                alert("读取失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}


//问卷查看
var fnTrQuestionnaireCheck = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var questionnaireName = record._oData["QuestionnaireName"];
    var url = "../TR/Questionnaire.aspx?id=" + record.getData(const_entityID) + "&questionnaireName=" + questionnaireName + "&flag=view";
    var pagetitle = "问卷调查_" + questionnaireName;
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI(url));
    parent.NeedRefreshPage = this;
}

//问卷统计
var fnTrQuestionTj = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var url = "../TR/QuestionnaireStatistics.aspx?r=" + Math.random() + "&id=" + record.getData(const_entityID);
    var pagetitle = "问卷统计_" + record._oData["QuestionnaireName"];
    var deptName = record._oData["DeptName"];
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI(url));
    parent.NeedRefreshPage = this;

}

//问卷复制
var fnCopy = function () {
    //debugger;
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    document.getElementById("EditUIWindow").src = "../TR/QuestionnaireCopy.aspx?r=" + Math.random() + "&id=" + record.getData(const_entityID);
    SetDWH(300, 120, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
    parent.NeedRefreshPage = this;
}
